﻿using System;
using Rhino.Mocks;

namespace Framework.Testing
{
    public static class MockRepositoryExtension
    {
        public static  MockRepository DoSetup<T>(this MockRepository mocks, 
            T anyMock, bool removeBehavior, Action setupAction)
        {
            var isRecord = !mocks.IsInReplayMode(anyMock);
            if (isRecord) 
                mocks.ReplayAll();
            
            setupAction();
            
            if (isRecord) 
                mocks.BackToRecordAll(removeBehavior ? BackToRecordOptions.All : BackToRecordOptions.None);
            return mocks;
        }
    }
}